//
//  MyOnlineCustomServiceController.m
//  FD
//
//  Created by xiaofang wang on 2018/12/3.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "MyOnlineCustomServiceController.h"

//view
#import "MyCustomServiceCell.h"

//controller
#import "ServiceViewController.h"
#import "MyFadeBackViewController.h" //意见反馈

@interface MyOnlineCustomServiceController ()<UITableViewDelegate,UITableViewDataSource>

/**REPORY_AN_ISSUE*/
@property (nonatomic, strong) UILabel *REPORY_AN_ISSUELb;


/**表格*/
@property (nonatomic, strong) UITableView *tableView;
/**数据源*/
@property (nonatomic, strong) NSArray *dataArr;

/**详细信息数据源*/
@property (nonatomic, strong) NSArray *detailArr;
/**bottomButton*/
@property (nonatomic, strong) UIButton *bottomButton;


@end

@implementation MyOnlineCustomServiceController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = NSLocalizedString(My_online_service, @"在线客服");
    
    [self initDataArray];
    
    [self setupUI];
    
}

- (void)setupUI {
    self.view.backgroundColor = kMainLightGrayColor;
    
    [self.view addSubview:self.REPORY_AN_ISSUELb];
    [self.view addSubview:self.tableView];
    [self.view addSubview:self.bottomButton];
    self.tableView.tableFooterView = [UIView new];

    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self setupLayout];
}

- (void)setupLayout {

    [self.REPORY_AN_ISSUELb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(FD_NavH);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(60);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(15);
        make.right.equalTo(self.view.mas_right).offset(-15);
        make.top.equalTo(self.REPORY_AN_ISSUELb.mas_bottom);
        make.bottom.equalTo(self.bottomButton.mas_top).offset(-20);
    }];
    
    [self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(50);
        make.bottom.equalTo(self.view.mas_bottom).offset(FD_TabbarSafeBottomMargin);
    }];
}



- (void)initDataArray {
    self.dataArr = @[@"How does FUDI & MORE work?",
                     @"What is FUDI operating hours",
                     @"What if I have food allergies and/or want to change the order?",
                     @"How much does the delivery fee cost?",
                     @"What is the estimated time of delivery?",
                     @"Where do I collect my food? ",
                     @"What is the cancellation policy?",
                     @"How can I get free food?",
                     @"Can I Tip the driver?"];
    
    
    self.detailArr = @[@"Download the app, sign up by your phonenumber and delivery address, choose from the food menu, meal kit option andgroceries option. Place your order and follow along as your food is prepared, your goods are packed and delivered",
                       @"12noon-11pm",
                       @"You may request \n modifications to a dish’s ingredients and preparation. Use the Special instructions \n field to include any food allergies you have or requests to have a dish prepared \n on the food order page",
                       @"Each delivery is €2.",
                       @"The time estimate of 40 minutes includes the counter accept and prepare an average order and time it should take for your food to be delivered to you. However, this is our best estimate, the actual delivery times may fluctuate depending on how busy the restaurant is, how large your order is, traffic conditions and other factors.",
                       @"In most cases, your food will be delivered right to your door. If your address is difficult to get to, it may be faster and easier for everyone if you meet your delivery outside by the street. You may also include special delivery instructions before confirming your order. You are able to track the driver, contact the driver on the order tracking screen. However, driver may not answer the phone or reply message via they are driving",
                       @"You can cancel your order anytime after submitting the order but before the counter accepts the order by tapping “Cancel order” in the order tracking screen. If you would like to cancel an order after an order has been accepted by the counter, you will need to call FUDI & More. Our team will then confirm with the kitchen that they have not begun preparing your food and are okay with cancellation. If the kitchen has started preparing the food we will unable to issue full refund for the order.",
                       @"Share your FUDI promo code with friends and get free food. You will find your promo code in the app, use the share buttons on the free food page or copy/paste the code onto emails, social media. When your friend makes their first order using the code, a promo code will be applied to your account. This promo code will automatically apply to your current or next order and expires after 6 months if not used.",
                       @"FUDI & More does not require customer to offer tip, you are welcome to do so. Should you choose to tip, the driver is welcome to accept or decline."];
}


#pragma mark- getter
- (UILabel *)REPORY_AN_ISSUELb {
    if (!_REPORY_AN_ISSUELb) {
        _REPORY_AN_ISSUELb = [[UILabel alloc] init];
        _REPORY_AN_ISSUELb.text = @"FAQs";
        _REPORY_AN_ISSUELb.textAlignment = NSTextAlignmentCenter;
        _REPORY_AN_ISSUELb.textColor = kLightGrayTextColor;
    }
    return _REPORY_AN_ISSUELb;
}


- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        _tableView.estimatedRowHeight = 44; 
        //注册
        [_tableView registerNib:[UINib nibWithNibName:@"MyCustomServiceCell" bundle:nil] forCellReuseIdentifier:@"MyCustomServiceCell"];
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        
        //取消线
        _tableView.showsVerticalScrollIndicator = NO;
    }
    return _tableView;
}

- (UIButton *)bottomButton {
    if (!_bottomButton) {
        _bottomButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_bottomButton setTitle:@"I have different question" forState:(UIControlStateNormal)];
        [_bottomButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        _bottomButton.backgroundColor = kMainRedColor;
        [_bottomButton addTarget:self action:@selector(clickbottomBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _bottomButton;
}
- (void)clickbottomBtnAction:(UIButton *)btn {
    MyFadeBackViewController *feedVC  = [[MyFadeBackViewController alloc] init];
    
    [self.navigationController pushViewController:feedVC animated:YES];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyCustomServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCustomServiceCell"];
    cell.nameLb.text = self.dataArr[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ServiceViewController *serviceVC = [[ServiceViewController alloc] initWithNibName:@"ServiceViewController" bundle:nil];
    
    //赋值
    serviceVC.title = self.dataArr[indexPath.row];
    serviceVC.detailStr = self.detailArr[indexPath.row];
    
    [self.navigationController pushViewController:serviceVC animated:YES];
}

@end
